/*
 * @LastEditors: 杜康
 * @LastEditTime: 2021-10-01 17:51:49
 */
// 回文检查
class Deque {
    constructor () {
        this.count = 0
        this.lowestCount = 0
        this.items = {}
    }
    addFront (element) {
        if (this.isEmpty()) {
            return undefined
        } else if (this.lowestCount > 0) {
            this.lowestCount -= 1
            this.items[this.lowestCount] = element
        } else {
            for (let i = this.count; i > 0; i--) {
                this.items[i] = this.items[i - 1]
            }
            this.count += 1
            this.lowestCount = 0
            this.items[0] = element
        }
    }
    addBack (element) {
        this.items[this.count] = element
        this.count += 1
    }
    removeFront () {
        if (this.isEmpty()) {
            return undefined
        }
        const result = this.items[this.lowestCount]
        delete this.items[this.lowestCount]
        this.lowestCount += 1
        return result
    }
    removeBack () {
        if (this.isEmpty()) {
            return undefined
        }
        const result = this.items[this.items.length - 1]
        delete this.items[this.items.length - 1]
        return result
    }
    peekFront () { }
    peekBack () { }
    isEmpty () {
        return this.count - this.lowestCount === 0
    }
    size () {
        return this.count - this.lowestCount
    }
    clear () {
        this.items = {}
        this.lowestCount = 0
        this.count = 0
    }
    toString () {
        if (this.isEmpty()) {
            return ''
        }
        let objString = `${this.items[this.lowestCount]}`
        for (let i = this.lowestCount + 1; i < this.count; i++) {
            objString = `${objString},${this.items[i]}`
        }
        return objString
    }
}
function palindromeChecker (aString) {
    if (aString === undefined ||
        aString === null ||
        (aString !== null && aString.length === 0)
    ) {
        return false
    }
    const deque = new Deque()
    const lowerString = aString.toLocaleLowerCase().split('').join(',')
    let isEqual = true
    let firstChar, lastChar
    for (let i = 0; i < lowerString.length; i++) {
        deque.addBack(lowerString.charAt(i))
    }
    console.log(deque)
    while (deque.size() > 1 && isEqual) {
        console.log(deque.removeBack())
        // firstChart = deque.removeFront()
        // console.log(firstChar)
        // lastChar = deque.removeBack()
        // console.log(lastChar)
        // if (firstChar !== lastChar) {
        //     isEqual = false
        // }
    }
    return isEqual
}

// console.log('a', palindromeChecker('a'))
console.log('aa', palindromeChecker('aa'))